package com.shop.user.service.login.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.modular.constant.BaseCodeDesc;
import com.modular.exception.ModularException;
import com.shop.user.dao.SysUserMapper;
import com.shop.user.model.SysUser;
import com.shop.user.service.login.ILoginService;
import com.shop.user.vo.login.LoginReqVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements ILoginService {
    @Autowired
    private SysUserMapper sysUserMapper;
    /**
     * 用户登录信息
     * @param reqVo
     */
    @Override
    public void login(LoginReqVo reqVo)
    {
        LambdaQueryWrapper<SysUser> query = new LambdaQueryWrapper<>();
        query.eq(SysUser::getUserAccount,reqVo.getLoginName());
        SysUser sysUser = sysUserMapper.selectOne(query);
        if(ObjectUtil.isNull(sysUser)){
            throw new ModularException(BaseCodeDesc.DEFATUL_MSG,"登录失败");
        }
        if(ObjectUtil.notEqual(sysUser.getUserPwd(),reqVo.getLoginPwd())){
            throw new ModularException(BaseCodeDesc.DEFATUL_MSG,"登录失败");
        }
    }
}
